package org.study.neo4j.boot.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.study.neo4j.boot.model.Teacher;
import org.study.neo4j.boot.repository.TeacherRepository;

import java.util.List;

/**
 * 作用描述
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2025年04月09日
 */
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Service
public class TeacherService {
    private final TeacherRepository teacherRepository;

    public Teacher saveTeacher(Teacher teacher) {
        return teacherRepository.save(teacher);
    }

    public List<Teacher> getAllTeachers() {
        return teacherRepository.findAll();
    }

    public Teacher getTeacherById(Long id) {
        return teacherRepository.findById(id).orElse(null);
    }

    public Teacher getTeacherByCourseCode(String courseCode) {
        return teacherRepository.findByCourseCode(courseCode);
    }

    public List<Teacher> getAdvisorsByStudentName(String studentName) {
        return teacherRepository.findAdvisorsByStudentName(studentName);
    }

    public void deleteTeacher(Long id) {
        teacherRepository.deleteById(id);
    }
}
